﻿/*  ----------------------------------------------------------------------------
 *  Microsoft Public License (http://www.microsoft.com/opensource/licenses.mspx#Ms-PL)
 *  
 *  ----------------------------------------------------------------------------
 *  DynamicAspect
 *  ----------------------------------------------------------------------------
 *  File:       IAspect.cs
 *  Author:     NiceWk (n9walker@hotmail.com)
 *  ----------------------------------------------------------------------------
 */

using System;
using System.Collections.Generic;

namespace Bizall.Dynamic.Aspect
{
    /// <summary>
    /// Define contract methods that will be implemented by instance aspect object.
    /// </summary>
    public interface IAspect
    {
        /// <summary>
        /// The method be called before enter the target method.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnBeforeMethodCall(WeavingContext context);

        /// <summary>
        /// The method indecates if OnAroundMethod should be call in target weaving context. <seealso cref="OnAroundMethodCall"/>
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        /// <returns>Return true if OnAroundMethodCall should be called,  otherwise return false.</returns>
         bool HasArroundMethod(WeavingContext context);

       /// <summary>
        /// The method be used to replace target method when calling to target method. Wheather the method be called is detemined by HasAroundMethod.<seealso cref="HasAroundMethod"/>
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnAroundMethodCall(WeavingContext context);

        /// <summary>
        /// The method be called after enter the target method.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnAfterMethodCall(WeavingContext context);

        /// <summary>
        /// The method is used to handle exception if there is any exception be thown out from target calling context.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        /// <param name="ex">The exception object.</param>
        ///<returns>true if exception has handled and does not need to process again, otherwise return false.</returns>
        bool OnExceptionMethodCall(WeavingContext context, Exception ex);

        /// <summary>
        ///  The method will be calling before sets value to property of target object.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnPropertyChanging(WeavingContext context);

        /// <summary>
        /// The method will be calling after sets value to property of target object.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnPropertyChanged(WeavingContext context);

        /// <summary>
        /// The method will be calling before read value to property of target object.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnBeforeGetValue(WeavingContext context);

        /// <summary>
        /// The method will be calling after read value to property of target object.
        /// </summary>
        /// <param name="context">The parameter contains call site info, as well as meta binder info.<see cref="WeavingContext" /></param>
        void OnAfterGetValue(WeavingContext context);

        /// <summary>
        /// A collection of regex pattern that be used to match a target class.
        /// </summary>
        List<string> Targets { get; }

        /// <summary>
        ///  Test to see if it is match for a given target class name.
        /// </summary>
        /// <param name="target">Be tested target class name</param>
        /// <returns>Return true at least a match existing, otherwise return false.</returns>
        bool IsMatch(string target);

        /// <summary>
        /// Specifies calling sequency for the method. The default value is -1 that indeciate the method would be called in uncertain order.
        /// </summary>
        int Sequence { get; set; }

        /// <summary>
        /// A switch that turn on/off  aspect object make effect.
        /// </summary>
        bool Enabled { get; set; }
    }
}